package com.tongyi.lizhishop.activitys;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.tongyi.lizhishop.beans.BillItemBean;
import com.wuhenzhizao.titlebar.widget.CommonTitleBar;
import com.zhy.adapter.recyclerview.CommonAdapter;

import com.tongyi.lizhishop.R;
import com.tongyi.lizhishop.common.BaseActivity;
import com.tongyi.lizhishop.fragment.ConsumeDetailFragment;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ConsumeDetailActivity extends BaseActivity {


    @BindView(R.id.titlebar)
    CommonTitleBar titlebar;
    @BindView(R.id.today)
    TextView today;
    @BindView(R.id.currentMonth)
    TextView currentMonth;
    @BindView(R.id.all)
    TextView all;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    private CommonAdapter<BillItemBean.ArrayBean> adapter;
    String day = "1";

    Map<Integer, Fragment> map = new HashMap();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_consume_detail_parent);
        ButterKnife.bind(this);
        initTitleBarView(titlebar, "明细");
//        titlebar.getRightTextView().setText("清空");
        initViewPager();

    }

    private void initViewPager() {
        viewpager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                Fragment fragment = map.get(position);
                if (fragment == null) {
                    fragment = ConsumeDetailFragment.newInstance(position, "");
                    map.put(position, fragment);
                }
                return fragment;
            }

            @Override
            public int getCount() {
                return 3;
            }
        });
        viewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                enable();
                if (position == 0) {
                    today.setEnabled(false);
                } else if (position == 1) {
                    currentMonth.setEnabled(false);
                } else {
                    all.setEnabled(false);
                }

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }


    public void enable() {
        currentMonth.setEnabled(true);
        all.setEnabled(true);
        today.setEnabled(true);
    }

    @OnClick({R.id.titlebar, R.id.today, R.id.currentMonth, R.id.all})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.titlebar:
                break;
            case R.id.today:
                enable();
                view.setEnabled(false);
                viewpager.setCurrentItem(0);
                break;
            case R.id.currentMonth:
                enable();
                view.setEnabled(false);
                viewpager.setCurrentItem(1);
                break;
            case R.id.all:
                enable();
                view.setEnabled(false);
                viewpager.setCurrentItem(2);
                break;
        }
    }
}
